<template>
    <div class="app-container">

        <el-form :inline="true" class="demo-form-inline caozuo">

            <el-form-item>
                <el-input v-model="searchObj.orderNo" placeholder="请输入订单编号" />
            </el-form-item>

            <el-form-item>
                <el-input v-model="searchObj.mobile" placeholder="请输入订单手机号" />
            </el-form-item>

            <el-form-item>
                <el-input v-model="searchObj.nickname" placeholder="请输入订单人姓名" />
            </el-form-item>

            <el-form-item>
                <el-input v-model="searchObj.title" placeholder="请输入产品名称" />
            </el-form-item>


            <el-button type="primary" icon="el-icon-search" @click="fetchData()">查询</el-button>
            <el-button type="default" @click="resetData()">清空</el-button>
        </el-form>

        <el-table v-loading="listLoading" :data="list" element-loading-text="数据加载中" border fit highlight-current-row
            row-class-name="myClassList">
            <el-table-column label="序号" width="70" align="center">
                <template slot-scope="scope">
                    {{ (page - 1) * limit + scope.$index + 1 }}
                </template>
            </el-table-column>

            <el-table-column label="订单信息" width="470" align="center">
                <template slot-scope="scope">
                    <el-descriptions class="margin-top" title="" :column="1" :size="size">
                        <el-descriptions-item label="课程名称">{{ scope.row.title }}</el-descriptions-item>
                        <el-descriptions-item label="授课讲师">{{ scope.row.teacherName }}</el-descriptions-item>
                        <el-descriptions-item label="订单金额">{{ scope.row.price }}</el-descriptions-item>
                    </el-descriptions>
                </template>
            </el-table-column>

            <el-table-column label="用户信息" align="center">
                <template slot-scope="scope">
                    <el-descriptions class="margin-top" title="" :column="1" :size="size">
                        <el-descriptions-item label="用户名">{{ scope.row.nickname }}</el-descriptions-item>
                        <el-descriptions-item label="手机号">{{ scope.row.mobile }}</el-descriptions-item>
                    </el-descriptions>
                </template>
            </el-table-column>

            <el-table-column prop="buyCount" label="订单状态" width="100" align="center">
                <template slot-scope="scope">

                    <div v-if="scope.row.status == '0'">
                        <el-tag class="style1" size="big" type="danger">没有支付</el-tag>
                    </div>
                    <div v-if="scope.row.status == '1'">
                        <el-tag class="style1" size="big" type="success">已经支付</el-tag>
                    </div>

                </template>
            </el-table-column>

            <el-table-column label="操作订单" width="150" align="center">
                <template slot-scope="scope">
                    <span @click="updateOrderInfo(scope.row.orderId)">
                        <el-button type="text" size="mini" icon="el-icon-edit">修改订单信息</el-button>
                    </span>
                    <span @click="viewOrderInfo(scope.row.orderId)">
                        <el-button type="text" size="mini" icon="el-icon-goods">查看订单信息</el-button>
                    </span>
                    <el-button type="text" size="mini" icon="el-icon-delete"
                        @click="deleteOrder(scope.row.orderId)">删除订单</el-button>
                </template>
            </el-table-column>
        </el-table>


        <!-- 分页 -->
        <el-pagination :current-page="page" :page-size="limit" :total="total" style="padding: 30px 0; text-align: center;"
            layout="total, prev, pager, next, jumper" @current-change="fetchData" />
    </div>
</template>
<script>
import order from '@/api/edu/order'

export default {

    data() {
        return {
            listLoading: true, // 是否显示loading信息
            list: null, // 数据列表
            total: 0, // 总记录数
            page: 1, // 页码
            limit: 5, // 每页记录数
          
            searchObj: {
                orderNo: '',
                mobile: '',
                nickname: '',
                title: '',
            }, // 查询条件
        }
    },

    created() {
        // 当页面加载时获取数据
        this.fetchData()

    },

    methods: {

        // 点击查询按钮执行的方法
        fetchData(page = 1) {
            this.page = page
            this.listLoading = true
            order.getPageList(this.page, this.limit, this.searchObj).then(response => {
                if (response.success === true) {
                    this.list = response.data.rows
                    this.total = response.data.total
                }
                this.listLoading = false
            })
        },

        resetData() {
            this.searchObj = {}
            this.fetchData()
        },

        // 点击更新订单按钮执行的方法
        updateOrderInfo(orderId) {
            this.$router.push({ path: '/order/update/' + orderId })
        },

        //点击查看订单信息执行的方法
        viewOrderInfo(orderId) {
            this.$router.push({ path: '/order/info/' + orderId })
        },

        // 点击删除订单执行的方法
        deleteOrder(orderId) {
            this.$confirm('此操作将删除该条订单, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                order.deleteOrder(orderId)
                    .then(response => {
                        console.log(56666)
                        // 提示信息
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        // 刷新页面
                        this.fetchData();
                    })
            })
        },

    }
}
</script>

<style scoped>
.myClassList .info {
    width: 450px;
    overflow: hidden;
}

.myClassList .info .pic {
    width: 150px;
    height: 90px;
    overflow: hidden;
    float: left;
}

.myClassList .info .pic a {
    display: block;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}

.myClassList .info .pic img {
    display: block;
    width: 100%;
}

.myClassList td .info .title {
    width: 280px;
    float: right;
    height: 90px;
}

.myClassList td .info .title a {
    display: block;
    height: 48px;
    line-height: 24px;
    overflow: hidden;
    color: #00baf2;
    margin-bottom: 12px;
}

.myClassList td .info .title p {
    line-height: 20px;
    margin-top: 5px;
    color: #818181;
}

.caozuo {
    /* transform: scale(0.8); */
}
</style>

   
